#!/bin/sh

# Here are the instructions used for this code:
# http://google-opensource.blogspot.com/2008/05/export-git-project-to-google-code.html

# I've also read through these alternative solutions:
# http://www.codeography.com/2010/03/17/howto-mirror-git-to-subversion.html
# http://www.kerrybuckley.org/2009/10/06/maintaining-a-read-only-svn-mirror-of-a-git-repository/
# http://sandrotosi.blogspot.com/2010/02/migrate-git-repo-to-svn-one.html
# http://eikke.com/importing-a-git-tree-into-a-subversion-repository/

# aptitude --without-recommends install subversion git-core git-svn

USERNAME=bkil

TMPREPO=$PWD/tmpgit
SRCREPO=file://$PWD/src/LabelMoviE
DESTNAME=out
DESTDIR=$PWD/$DESTNAME
DESTREPO=file://$DESTDIR

git config --global user.name "bkil" ||exit 1
git config --global user.email "http://bkil.hu/contact/" ||exit 1

[ -e "$DESTDIR" ] && exit 1
[ -e "$TMPREPO" ] && exit 1

svnadmin create $DESTDIR ||exit 1
svn -m ".branches created" mkdir $DESTREPO/.branches ||exit 1

mkdir -p $TMPREPO ||exit 1
cd $TMPREPO ||exit 1

git svn clone --username $USERNAME $DESTREPO ||exit 1
cd $DESTNAME ||exit 1
git fetch $SRCREPO ||exit 1

git branch tmp $(cut -b-40 .git/FETCH_HEAD) ||exit 1
git tag -a -m "Last fetch" last tmp ||exit 1

INIT_COMMIT=$(git log tmp --pretty=format:%H | tail -1)
git checkout $INIT_COMMIT . ||exit 1
git commit -C $INIT_COMMIT ||exit 1

git rebase master tmp ||exit 1
git branch -M tmp master ||exit 1

git svn --rmdir --find-copies-harder --add-author-from --use-log-author dcommit ||exit 1
